home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS08.ADF
/
C
/
SetAlternate.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-04-02
|
4KB
|
136 lines
/* SetAlternate.c */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* (c) Copyright 1986 John A. Toebes, VIII All rights reserved */
/* 120-H Northington Place, Cary NC 27511 (919) 469-4210 */
/* This program may be used and modified for any purpose so long as */
/* this copyright notice remains with the code and the program is not */
/* sold and no charge is made for its use. */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
In making some enhancements to the Icons for Hack, I wrote a very simple
utility that you may find useful. Normally, the Icon editor only lets you
create icons whose selected action is either to reverse the image or provide
backfill.However, in the gadget structure for the Icon is the ability to put
an alternate image as found in any gadget. To use it you simply have to
supply an alternate image and set the appropriate bits in the structure.
Unfortunately ICONED fails to provide an easy way to do this so I wrote a Q&D
tool to combine two icons into a single one with the second being an alternate
image for the first.
To use it, first compile the program (It works under Lattice, have no idea
about MANX) and link it.
Then create two icons for the one you want. Make the first the normal image
and the second the alternate image. When saving them make sure you set the
frame the same for both or the results will be an alternate image slightly
out of wack (and I don't mean the debugger) with the first. Lets assume
the first is called 'primary' and the second 'alternate'. At this point
there will be four files on disk:
primary
primary.info
secondary
secondary.info
Now run the SetAlternate program with
SetAlternate primary secondary
The primary icon will now display the second one when you hit on it. Note
that since the image was copied, you can delete the second one ('secondary'
in this case) without any effect. Note however that ICONED does not know
exactly what to do with the alternate image so you lose it if you edit the
Icon. Have no fear, just run the program again to reset the alternate. Also
there are no side effects from running SetAlternate over and over on the
same icons (other than waste time).
*/
#include <stdio.h>
#include <exec/types.h>
#include <workbench/workbench.h>
#include <workbench/icon.h>
#include <workbench/startup.h>
int IconBase;
extern struct WBStartup *WBenchMsg;
main(argc,argv)
int argc;
char *argv[];
{
struct DiskObject *diskobja, *diskobj, *GetDiskObject();
APTR saveimage;
USHORT saveflags;
/* make sure we ran from CLI */
if (argc == 0)
exit(1);
/* make sure they specified two icons */
if (argc != 3)
{
printf("Usage: %s <icon> <icona>\n", argv[0]);
exit(2);
}
/* make the icon library available to us */
if ( (IconBase = OpenLibrary( ICONNAME, 1)) == NULL)
exit(2);
/* read the icon to modify from disk */
if ( (diskobj = GetDiskObject(argv[1])) == NULL)
{
printf("Cannot read icon for %s\n", argv[1]);
CloseLibrary( IconBase );
exit(3);
}
/* read the second icon to get its image */
if ( (diskobja = GetDiskObject(argv[2])) == NULL)
{
printf("Cannot read icon for %s\n", argv[1]);
FreeDiskObject(diskobj);
CloseLibrary( IconBase );
exit(4);
}
/* remember what the original icon looked like */
/* we will restore it before we do a FreeDiskObject on it */
/* this way the system won't get confused as to which memory it */
/* allocated for the structure */
saveimage = diskobj->do_Gadget.SelectRender;
saveflags = diskobj->do_Gadget.Flags;
/* point the alternate image of the modified icon to that of the 2nd icon */
diskobj->do_Gadget.SelectRender = diskobja->do_Gadget.GadgetRender;
/* modify the flags so that it used the alternate image */
diskobj->do_Gadget.Flags = (saveflags & ~GADGHIGHBITS) | GADGHIMAGE;
/* now write the fixed icon to disk */
if ( !PutDiskObject( argv[1], diskobj) )
printf("Cannot write new icon - code %d\n", IoErr() );
/* restore the original icon to what we read in */
diskobj->do_Gadget.SelectRender = saveimage;
diskobj->do_Gadget.Flags = saveflags;
/* and send it and the other object away */
if ( diskobj)
FreeDiskObject( diskobj );
if ( diskobja)
FreeDiskObject( diskobja );
if ( IconBase)
CloseLibrary( IconBase );
}